package br.cin.ufpe.corba.namingservice.binding;

import java.io.Serializable;

import br.cin.ufpe.corba.namingservice.NameComponent;

public class Binding implements Serializable {
	
	private static final long serialVersionUID = -5472395473821797172L;
	
	private NameComponent name;	
	private BindingType type;	

	public Binding(NameComponent name, BindingType type) {
		super();
		this.name = name;
		this.type = type;
	}

	public NameComponent getName() {
		return name;
	}

	public void setName(NameComponent name) {
		this.name = name;
	}

	public BindingType getType() {
		return type;
	}

	public void setType(BindingType type) {
		this.type = type;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		if (type == BindingType.CONTEXT) {
			sb.append("Context: ");
		}
		else {
			sb.append("Object: ");
		}
		
		sb.append(name.toString());
		
		return sb.toString();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof Binding) {
			return this.name.equals(((Binding) obj).name);
		}
		return false;
	}
	
	@Override
	public int hashCode() {		
		return this.name.hashCode();
	}
}
